home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / The GIMP 2.2.8 / gimp-2.2.8-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / slide.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2005-06-30  |  7.1 KB  |  248 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; This program is free software; you can redistribute it and/or modify
  4. ; it under the terms of the GNU General Public License as published by
  5. ; the Free Software Foundation; either version 2 of the License, or
  6. ; (at your option) any later version.
  7. ; This program is distributed in the hope that it will be useful,
  8. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. ; GNU General Public License for more details.
  11. ; You should have received a copy of the GNU General Public License
  12. ; along with this program; if not, write to the Free Software
  13. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. ;
  15. ;
  16. ; slide.scm   version 0.41   2004/03/28
  17. ;
  18. ; CHANGE-LOG:
  19. ; 0.20 - first public release
  20. ; 0.30 - some code cleanup
  21. ;        now uses the rotate plug-in to improve speed
  22. ; 0.40 - changes to work with gimp-1.1 
  23. ;        if the image was rotated, rotate the whole thing back when finished
  24. ; 0.41 - changes to work with gimp-2.0, slightly correct text offsets,
  25. ;        Nils Philippsen <nphilipp@redhat.com> 2004/03/28
  26. ;
  27. ; !still in development!
  28. ; TODO: - change the script so that the film is rotated, not the image
  29. ;       - antialiasing
  30. ;       - make 'add background' an option
  31. ;       - ?
  32. ;
  33. ; Copyright (C) 1997-1999 Sven Neumann <sven@gimp.org>
  34. ;  
  35. ; makes your picture look like a slide
  36. ;
  37. ; The script works on RGB and grayscale images that contain only 
  38. ; one layer. The image is cropped to fit into an aspect ratio of 1:1,5.
  39. ; It creates a copy of the image or can optionally work on the original. 
  40. ; The script uses the current background color to create a background 
  41. ; layer.
  42.  
  43.  
  44. (define (crop width height ratio)
  45.   (cond ((>= width (* ratio height)) (* ratio height))
  46.     ((< width (* ratio height))   width)))
  47.  
  48.  
  49. (define (script-fu-slide img
  50.              drawable
  51.              text
  52.              number
  53.              fontname
  54.              font-color
  55.              work-on-copy)
  56.   (let* ((type (car (gimp-drawable-type-with-alpha drawable)))
  57.      (image (cond ((= work-on-copy TRUE)
  58.                (car (gimp-image-duplicate img)))
  59.               ((= work-on-copy FALSE)
  60.                img)))
  61.      (owidth (car (gimp-image-width image)))
  62.      (oheight (car (gimp-image-height image)))
  63.      (ratio (if (>= owidth oheight) (/ 3 2)
  64.                                 (/ 2 3)))
  65.      (crop-width (crop owidth oheight ratio))
  66.      (crop-height (/ crop-width ratio))
  67.      (width (* (max crop-width crop-height) 1.05))
  68.      (height (* (min crop-width crop-height) 1.5))
  69.      (hole-width (/ width 20))
  70.      (hole-space (/ width 8))
  71.      (hole-height (/ width 12))
  72.      (hole-radius (/ hole-width 4))
  73.      (hole-start (- (/ (rand 1000) 1000) 0.5))
  74.      (film-layer (car (gimp-layer-new image
  75.                       width
  76.                       height
  77.                       type
  78.                       "Film"
  79.                       100
  80.                       NORMAL-MODE)))
  81.      (bg-layer (car (gimp-layer-new image
  82.                     width
  83.                     height
  84.                     type
  85.                     "Background"
  86.                     100
  87.                     NORMAL-MODE)))
  88.      (pic-layer (car (gimp-image-get-active-drawable image)))
  89.      (numbera (string-append number "A")))
  90.  
  91.     (gimp-context-push)
  92.  
  93.     (gimp-image-undo-disable image)
  94.  
  95. ; add an alpha channel to the image
  96.     (gimp-layer-add-alpha pic-layer)
  97.  
  98. ; crop, resize and eventually rotate the image 
  99.     (gimp-image-crop image
  100.              crop-width
  101.              crop-height
  102.              (/ (- owidth crop-width) 2)
  103.              (/ (- oheight crop-height) 2))
  104.     (gimp-image-resize image
  105.                width
  106.                height
  107.                (/ (- width crop-width) 2)
  108.                (/ (- height crop-height) 2))
  109.     (if (< ratio 1) (plug-in-rotate 1
  110.                     image
  111.                     pic-layer
  112.                     1
  113.                     FALSE))
  114.  
  115. ; add the background layer
  116.     (gimp-drawable-fill bg-layer BACKGROUND-FILL)
  117.     (gimp-image-add-layer image bg-layer -1)
  118.  
  119. ; add the film layer
  120.     (gimp-context-set-background '(0 0 0))
  121.     (gimp-drawable-fill film-layer BACKGROUND-FILL)
  122.     (gimp-image-add-layer image film-layer -1)
  123.  
  124. ; add the text
  125.     (gimp-context-set-foreground font-color)
  126.     (gimp-floating-sel-anchor (car (gimp-text-fontname image
  127.                                film-layer
  128.                                (+ hole-start (* -0.25 width))
  129.                                (* 0.01 height)
  130.                                text
  131.                                0
  132.                                TRUE
  133.                                (* 0.040 height) PIXELS fontname)))
  134.     (gimp-floating-sel-anchor (car (gimp-text-fontname image
  135.                                film-layer
  136.                                (+ hole-start (* 0.75 width))
  137.                                (* 0.01 height)
  138.                                text
  139.                                0
  140.                                TRUE
  141.                                (* 0.040 height) PIXELS
  142.                                fontname )))
  143.     (gimp-floating-sel-anchor (car (gimp-text-fontname image
  144.                                film-layer
  145.                                (+ hole-start (* 0.35 width))
  146.                                0.0
  147.                                number
  148.                                0
  149.                                TRUE
  150.                                (* 0.050 height) PIXELS
  151.                                fontname )))
  152.     (gimp-floating-sel-anchor (car (gimp-text-fontname image
  153.                                film-layer
  154.                                (+ hole-start (* 0.35 width))
  155.                                (* 0.94 height)
  156.                                number
  157.                                0
  158.                                TRUE
  159.                                (* 0.050 height) PIXELS
  160.                                fontname )))
  161.     (gimp-floating-sel-anchor (car (gimp-text-fontname image
  162.                                film-layer
  163.                                (+ hole-start (* 0.85 width))
  164.                                (* 0.945 height)
  165.                                numbera
  166.                                0
  167.                                TRUE
  168.                                (* 0.045 height) PIXELS
  169.                                fontname )))
  170.     
  171. ; create a mask for the holes and cut them out
  172.     (let* ((film-mask (car (gimp-layer-create-mask film-layer ADD-WHITE-MASK)))
  173.        (hole hole-start)
  174.        (top-y (* height 0.06))
  175.        (bottom-y(* height 0.855)))
  176.  
  177.       (gimp-layer-add-mask film-layer film-mask)
  178.  
  179.       (gimp-selection-none image)
  180.       (while (< hole 8)
  181.          (gimp-rect-select image
  182.                    (* hole-space hole)
  183.                    top-y
  184.                    hole-width
  185.                    hole-height
  186.                    CHANNEL-OP-ADD
  187.                    FALSE
  188.                    0)
  189.          (gimp-rect-select image
  190.                    (* hole-space hole)
  191.                    bottom-y
  192.                    hole-width
  193.                    hole-height
  194.                    CHANNEL-OP-ADD
  195.                    FALSE
  196.                    0)
  197.          (set! hole (+ hole 1)))
  198.  
  199.       (gimp-context-set-foreground '(0 0 0))
  200.       (gimp-edit-fill film-mask BACKGROUND-FILL)
  201.       (gimp-selection-none image)
  202.       (plug-in-gauss-rle 1 image film-mask hole-radius TRUE TRUE)
  203.       (gimp-threshold film-mask 127 255)
  204.  
  205.       (gimp-layer-remove-mask film-layer MASK-APPLY))
  206.  
  207. ; reorder the layers
  208.     (gimp-image-raise-layer image pic-layer)
  209.     (gimp-image-raise-layer image pic-layer)
  210.  
  211. ; eventually rotate the whole thing back
  212.     (if (< ratio 1) 
  213.     (plug-in-rotate 1
  214.             image
  215.             pic-layer
  216.             3
  217.             TRUE))
  218.  
  219. ; clean up after the script
  220.     (gimp-selection-none image)
  221.     (gimp-image-undo-enable image)
  222.     (if (= work-on-copy TRUE)
  223.     (gimp-display-new image))
  224.     (gimp-displays-flush)
  225.  
  226.     (gimp-context-pop)))
  227.  
  228. (script-fu-register "script-fu-slide"
  229.             _"_Slide..."
  230.             "Gives the image the look of a slide"
  231.             "Sven Neumann <sven@gimp.org>"
  232.             "Sven Neumann"
  233.             "2004/03/28"
  234.             "RGB GRAY"
  235.             SF-IMAGE    "Image"         0
  236.             SF-DRAWABLE "Drawable"      0
  237.             SF-STRING   _"Text"         "The GIMP"
  238.             SF-STRING   _"Number"       "32"
  239.             SF-FONT     _"Font"         "Serif"
  240.             SF-COLOR    _"Font color"   '(255 180 0)
  241.             SF-TOGGLE   _"Work on copy" TRUE)
  242.  
  243. (script-fu-menu-register "script-fu-slide"
  244.              _"<Image>/Script-Fu/Decor")
  245.